//
//  HERetrunLogGoodsCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/11/16.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HERetrunLogGoodsCell.h"

@interface HERetrunLogGoodsCell ()

@property (nonatomic, strong) UIImageView *goodsimgView;
@property (nonatomic, strong) UIImageView *selectBtn;
@property (nonatomic, strong) UILabel *titleLb;
@property (nonatomic, strong) UILabel *priceLb;
@property (nonatomic, strong) UILabel *skuLb;
@property (nonatomic, strong) UILabel *countLb;

@end

@implementation HERetrunLogGoodsCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
 
        [self initUI];
    }
    return self;
}

- (void)initUI {


    UIView *warp = [UIView new];
    warp.backgroundColor = KWhiteColor;
    [self.contentView addSubview:warp];

    [warp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(1);
        make.left.equalTo(self.contentView);
        make.right.equalTo(self.contentView);
//        make.height.mas_greaterThanOrEqualTo(120);
        make.bottom.equalTo(self.contentView).mas_offset(-1);
    }];

 
    // 商品图片
    _goodsimgView = [UIImageView new];
    _goodsimgView.contentMode = UIViewContentModeScaleAspectFill;
    [warp addSubview:_goodsimgView];
    _goodsimgView.userInteractionEnabled = YES;
    
    // 商品名称
    _titleLb = [UILabel new];
    _titleLb.text = @"-";
    _titleLb.font = DYFont(16);
    [warp addSubview:_titleLb];
    
    // 规格
    _skuLb = [UILabel new];
    _skuLb.text = @"规格：";
    _skuLb.font = DYFont(14);
    _skuLb.numberOfLines = 0;
    _skuLb.textColor = UIColor.lightGrayColor;
    [warp addSubview:_skuLb];
    
    
    // 价格
    _priceLb = [UILabel new];
    _priceLb.text = @"￥0.00";
    _priceLb.font = DYBlodFont(16);
    _priceLb.textColor = KHexColor(@"#FF5757");
    [warp addSubview:_priceLb];
    
    // 商品数量
    _countLb = [UILabel new];
    _countLb.text = @"x 0";
    _countLb.font = DYFont(15);
    _countLb.textColor = CNavSubTitleColor;
    [warp addSubview:_countLb];
       
    [_goodsimgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(warp).mas_offset(15);
        make.left.equalTo(warp).mas_offset(15);
        make.width.height.mas_offset(85);
        make.bottom.equalTo(warp.mas_bottom).offset(-10);
    }];
    [_goodsimgView hg_setAllCornerWithCornerRadius:6.0f];

    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_goodsimgView);
        make.left.equalTo(_goodsimgView.mas_right).mas_offset(15);
        make.right.equalTo(warp.mas_right).mas_offset(-15);
    }];
    
    [_skuLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLb.mas_bottom).mas_offset(5);
        make.left.equalTo(_titleLb.mas_left);
        make.right.equalTo(warp).mas_offset(-15);
    }];
    
    [_priceLb mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(_skuLb.mas_bottom).mas_offset(10);
        make.left.equalTo(_titleLb.mas_left);
        make.bottom.equalTo(_goodsimgView.mas_bottom).mas_offset(-0);
    }];
    
    [_priceLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    
    [_countLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_priceLb);
        make.left.equalTo(_priceLb.mas_right).mas_offset(15);
        make.right.equalTo(warp.mas_right).mas_offset(-5);
    }];
}

- (void)refreshContent:(GDFiterCellModel *)fiterModel formModel:(GDFormModel *)formModel indexPath:(NSIndexPath *)indexPath {
    
    HEOrderItemModel *model = self.formModel.od_itemList[indexPath.row];
    
    _titleLb.text = model.productName;
    [_goodsimgView sd_setImageWithURL:[NSURL URLWithString:model.productPic] placeholderImage:IMAGE_NAMED(@"noImage")];
    _skuLb.text = model.productAttr;
    _priceLb.text = [NSString stringWithFormat:@"￥%@", model.KproductPrice];
    _countLb.text = [NSString stringWithFormat:@" x%ld", model.productQuantity];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
